<?php
namespace app\api\model;
/** 
* Document
*/
class Theme extends Base {
    protected $hidden =['update_time','delete_time'];
    public function products(){
        return $this->belongsToMany('Product','theme_product','product_id','theme_id');
    }


    /**
     * 根据主键，获取专题完整信息
     *
     * @param int|string $id
     * @return array
     */
    public static function getCompleteInfo($id){
        $theme = self::get($id,['products']);
        if(empty($theme)) return [];
        
        $res = $theme->toArray();
        $res['topic_img'] = $theme->topic_img;
        $res['head_img'] = $theme->head_img;
        
        return $res;
    }

    
    /* ---------------图片的读取器------------------- */
    public function getTopicImgAttr($value,$data){
        return Image::getImgUrl($data['topic_img_id']);
    }
    
    public function getHeadImgAttr($value,$data){
        return Image::getImgUrl($data['head_img_id']);
    }
}